function Bdr = sort_border_node(E,ET)
% function Bdr = sort_border_node(E,ET)
% this function is used to sort border nodes in turn one-by-one connected
% the return value store the nodes' index in prescribed turn
% use the following code to check the validaty:
% ---------------------------------------------------
% plot(V(Bdr,1),V(Bdr,2),'r.'); hold on;
% text(V(Bdr,1),V(Bdr,2),num2str(Bdr));hold off;
% ---------------------------------------------------

% find the index of boundary edge
boundE = find(ET(:,2)==0);
% get its length
nbdr = length(boundE);
% temp boundary edge list
E_bound = E(boundE,:); 
% reserve spaces
Bdr = zeros(nbdr,1); 
% set the first node in boundary nodes list
Bdr(1) = E_bound(1,1);
start = E_bound(1,2);  % begin from the second node of current edges
eg = 1; % begin to find all boundary nodes
for i = 2:nbdr % after execute for nBdr-1 time, all the boundary nodes are found
    Bdr(i) = start;
    eg2 = find(E_bound(:,1)==start | E_bound(:,2)==start);
    if eg2(1) ~= eg
        eg = eg2(1);
    else
        eg = eg2(2);
    end
    % find next start nodes
    if E_bound(eg,1)==start
        start = E_bound(eg,2);
    else
        start = E_bound(eg,1);
    end
end